#数据库连接
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

# 修改成你自己的 MySQL 用户名/密码/数据库
DATABASE_URL = "mysql+pymysql://root:123456@127.0.0.1:3306/oj_system?charset=utf8mb4"
engine = create_engine(DATABASE_URL, connect_args={"check_same_thread": False})
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()

engine = create_engine(DATABASE_URL, echo=True)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

Base = declarative_base()

# 依赖项：在路由里调用数据库 session
def get_db():
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()
